package com.apollographql.apollo.api;

import com.apollographql.apollo.api.internal.ResponseReader;
import com.apollographql.apollo.subscription.ApolloOperationMessageSerializer;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.kt.Metadata;
import com.kt.TypeCastException;
import com.kt.collections.CollectionsKt;
import com.kt.jvm.functions.Function1;
import com.kt.jvm.internal.DefaultConstructorMarker;
import com.kt.jvm.internal.Intrinsics;
import com.kt.jvm.internal.Reflection;
import com.kt.text.Typography;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000j\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0006\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010 \n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\t\u0018\u00002\u00020\u0001:\u00011B-\b\u0016\u0012\u0014\u0010\u0002\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u0003\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nB;\b\u0002\u0012\u0014\u0010\u0002\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u0003\u0012\u0014\u0010\u000b\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u0003\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\fJ'\u0010\r\u001a\u0004\u0018\u0001H\u000e\"\u0004\b\u0000\u0010\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\b\u0010\u0011\u001a\u0004\u0018\u0001H\u000eH\u0002¢\u0006\u0002\u0010\u0012J\u0017\u0010\u0013\u001a\u0004\u0018\u00010\u00142\u0006\u0010\u000f\u001a\u00020\u0010H\u0016¢\u0006\u0002\u0010\u0015J!\u0010\u0016\u001a\u0004\u0018\u0001H\u0017\"\b\b\u0000\u0010\u0017*\u00020\u00052\u0006\u0010\u000f\u001a\u00020\u0018H\u0016¢\u0006\u0002\u0010\u0019J\u0017\u0010\u001a\u001a\u0004\u0018\u00010\u001b2\u0006\u0010\u000f\u001a\u00020\u0010H\u0016¢\u0006\u0002\u0010\u001cJ/\u0010\u001d\u001a\u0004\u0018\u0001H\u0017\"\b\b\u0000\u0010\u0017*\u00020\u00052\u0006\u0010\u000f\u001a\u00020\u00102\f\u0010\u001e\u001a\b\u0012\u0004\u0012\u0002H\u00170\u001fH\u0016¢\u0006\u0002\u0010 J\u0017\u0010!\u001a\u0004\u0018\u00010\"2\u0006\u0010\u000f\u001a\u00020\u0010H\u0016¢\u0006\u0002\u0010#J2\u0010$\u001a\f\u0012\u0006\u0012\u0004\u0018\u0001H\u0017\u0018\u00010%\"\b\b\u0000\u0010\u0017*\u00020\u00052\u0006\u0010\u000f\u001a\u00020\u00102\f\u0010&\u001a\b\u0012\u0004\u0012\u0002H\u00170'H\u0016J\u0017\u0010(\u001a\u0004\u0018\u00010)2\u0006\u0010\u000f\u001a\u00020\u0010H\u0016¢\u0006\u0002\u0010*J/\u0010+\u001a\u0004\u0018\u0001H\u0017\"\b\b\u0000\u0010\u0017*\u00020\u00052\u0006\u0010\u000f\u001a\u00020\u00102\f\u0010\u001e\u001a\b\u0012\u0004\u0012\u0002H\u00170\u001fH\u0016¢\u0006\u0002\u0010 J\u0012\u0010,\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u000f\u001a\u00020\u0010H\u0016J\u0010\u0010-\u001a\u00020\u00142\u0006\u0010\u000f\u001a\u00020\u0010H\u0002J6\u0010.\u001a\u0004\u0018\u0001H\u0017\"\u0006\b\u0000\u0010\u0017\u0018\u00012\u0014\u0010/\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u00032\u0006\u0010\u000f\u001a\u00020\u0010H\b¢\u0006\u0002\u00100R\u001c\u0010\u0002\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0004¢\u0006\u0002\n\u0000R\u001c\u0010\u000b\u001a\u0010\u0012\u0004\u0012\u00020\u0004\u0012\u0006\u0012\u0004\u0018\u00010\u00050\u0003X\u0004¢\u0006\u0002\n\u0000¨\u00062"}, d2 = {"Lcom/apollographql/apollo/api/internal/SimpleResponseReader;", "Lcom/apollographql/apollo/api/internal/ResponseReader;", "recordSet", "", "", "", ApolloOperationMessageSerializer.JSON_KEY_VARIABLES, "Lcom/apollographql/apollo/api/Operation$Variables;", "scalarTypeAdapters", "Lcom/apollographql/apollo/api/ScalarTypeAdapters;", "(Ljava/util/Map;Lcom/apollographql/apollo/api/Operation$Variables;Lcom/apollographql/apollo/api/ScalarTypeAdapters;)V", "variableValues", "(Ljava/util/Map;Ljava/util/Map;Lcom/apollographql/apollo/api/ScalarTypeAdapters;)V", "checkValue", "V", "field", "Lcom/apollographql/apollo/api/ResponseField;", "value", "(Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Object;)Ljava/lang/Object;", "readBoolean", "", "(Lcom/apollographql/apollo/api/ResponseField;)Ljava/lang/Boolean;", "readCustomType", "T", "Lcom/apollographql/apollo/api/ResponseField$CustomTypeField;", "(Lcom/apollographql/apollo/api/ResponseField$CustomTypeField;)Ljava/lang/Object;", "readDouble", "", "(Lcom/apollographql/apollo/api/ResponseField;)Ljava/lang/Double;", "readFragment", "objectReader", "Lcom/apollographql/apollo/api/internal/ResponseReader$ObjectReader;", "(Lcom/apollographql/apollo/api/ResponseField;Lcom/apollographql/apollo/api/internal/ResponseReader$ObjectReader;)Ljava/lang/Object;", "readInt", "", "(Lcom/apollographql/apollo/api/ResponseField;)Ljava/lang/Integer;", "readList", "", "listReader", "Lcom/apollographql/apollo/api/internal/ResponseReader$ListReader;", "readLong", "", "(Lcom/apollographql/apollo/api/ResponseField;)Ljava/lang/Long;", "readObject", "readString", "shouldSkip", "valueFor", "map", "(Ljava/util/Map;Lcom/apollographql/apollo/api/ResponseField;)Ljava/lang/Object;", "ListItemReader", "apollo-api"}, k = 1, mv = {1, 4, 0})
/* compiled from: SimpleResponseReader.kt */
public final class SimpleResponseReader implements ResponseReader {
    private final Map<String, Object> recordSet;
    private final ScalarTypeAdapters scalarTypeAdapters;
    private final Map<String, Object> variableValues;

    private SimpleResponseReader(Map<String, ? extends Object> map, Map<String, ? extends Object> map2, ScalarTypeAdapters scalarTypeAdapters2) {
        this.recordSet = (Map<String, Object>) map;
        this.variableValues = (Map<String, Object>) map2;
        this.scalarTypeAdapters = scalarTypeAdapters2;
    }

    public /* synthetic */ SimpleResponseReader(Map recordSet2, Map variableValues2, ScalarTypeAdapters scalarTypeAdapters2, DefaultConstructorMarker $constructor_marker) {
        this(recordSet2, variableValues2, scalarTypeAdapters2);
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> T readFragment(ResponseField field, Function1<? super ResponseReader, ? extends T> function1) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(function1, "block");
        return (T) DefaultImpls.readFragment(this, field, function1);
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> List<T> readList(ResponseField field, Function1<? super ResponseReader.ListItemReader, ? extends T> function1) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(function1, "block");
        return DefaultImpls.readList(this, field, function1);
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> T readObject(ResponseField field, Function1<? super ResponseReader, ? extends T> function1) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(function1, "block");
        return (T) DefaultImpls.readObject(this, field, function1);
    }

    /* JADX INFO: this call moved to the top of the method (can break code semantics) */
    public SimpleResponseReader(Map<String, ? extends Object> map, Operation.Variables variables, ScalarTypeAdapters scalarTypeAdapters2) {
        this(map, variables.valueMap(), scalarTypeAdapters2);
        Intrinsics.checkParameterIsNotNull(map, "recordSet");
        Intrinsics.checkParameterIsNotNull(variables, ApolloOperationMessageSerializer.JSON_KEY_VARIABLES);
        Intrinsics.checkParameterIsNotNull(scalarTypeAdapters2, "scalarTypeAdapters");
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public String readString(ResponseField field) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        String value = null;
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv != null) {
            if (value$iv instanceof String) {
                value = (String) value$iv;
            } else {
                throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(String.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
            }
        }
        return (String) checkValue(field, value);
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public Integer readInt(ResponseField field) {
        Number number;
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof BigDecimal)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(BigDecimal.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        BigDecimal value = (BigDecimal) value$iv;
        checkValue(field, value);
        if (value == null || (number = BigDecimalKt.toNumber(value)) == null) {
            return null;
        }
        return Integer.valueOf(number.intValue());
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public Long readLong(ResponseField field) {
        Number number;
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof BigDecimal)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(BigDecimal.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        BigDecimal value = (BigDecimal) value$iv;
        checkValue(field, value);
        if (value == null || (number = BigDecimalKt.toNumber(value)) == null) {
            return null;
        }
        return Long.valueOf(number.longValue());
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public Double readDouble(ResponseField field) {
        Number number;
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof BigDecimal)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(BigDecimal.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        BigDecimal value = (BigDecimal) value$iv;
        checkValue(field, value);
        if (value == null || (number = BigDecimalKt.toNumber(value)) == null) {
            return null;
        }
        return Double.valueOf(number.doubleValue());
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public Boolean readBoolean(ResponseField field) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Boolean value = null;
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv != null) {
            if (value$iv instanceof Boolean) {
                value = (Boolean) value$iv;
            } else {
                throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(Boolean.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
            }
        }
        return (Boolean) checkValue(field, value);
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> T readObject(ResponseField field, ObjectReader<T> objectReader) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(objectReader, "objectReader");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof Map)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(Map.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        Map value = (Map) value$iv;
        checkValue(field, value);
        if (value != null) {
            return objectReader.read(new SimpleResponseReader(value, this.variableValues, this.scalarTypeAdapters));
        }
        return null;
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> List<T> readList(ResponseField field, ListReader<T> listReader) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(listReader, "listReader");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof List)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(List.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        List values = (List) value$iv;
        checkValue(field, values);
        if (values == null) {
            return null;
        }
        List $this$map$iv = values;
        Collection destination$iv$iv = new ArrayList(CollectionsKt.collectionSizeOrDefault($this$map$iv, 10));
        Iterator<T> it = $this$map$iv.iterator();
        while (it.hasNext()) {
            Object item$iv$iv = it.next();
            destination$iv$iv.add(item$iv$iv != null ? listReader.read(new ListItemReader(this, field, item$iv$iv)) : null);
        }
        return (List) destination$iv$iv;
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> T readCustomType(ResponseField.CustomTypeField field) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        }
        checkValue(field, value$iv);
        if (value$iv != null) {
            return (T) this.scalarTypeAdapters.adapterFor(field.getScalarType()).decode(CustomTypeValue.Companion.fromRawValue(value$iv));
        }
        return null;
    }

    @Override // com.apollographql.apollo.api.internal.ResponseReader
    public <T> T readFragment(ResponseField field, ObjectReader<T> objectReader) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(objectReader, "objectReader");
        if (shouldSkip(field)) {
            return null;
        }
        Object value$iv = this.recordSet.get(field.getResponseName());
        if (value$iv == null) {
            value$iv = null;
        } else if (!(value$iv instanceof String)) {
            throw new ClassCastException("The value for \"" + field.getResponseName() + "\" expected to be of type \"" + Reflection.getOrCreateKotlinClass(String.class).getSimpleName() + "\" but was \"" + Reflection.getOrCreateKotlinClass(value$iv.getClass()).getSimpleName() + Typography.quote);
        }
        String value = (String) value$iv;
        checkValue(field, value);
        if (value == null) {
            return null;
        }
        Collection destination$iv$iv = new ArrayList();
        for (ResponseField.Condition condition : field.getConditions()) {
            T t = !(condition instanceof ResponseField.TypeNameCondition) ? null : (T) condition;
            if (t != null) {
                destination$iv$iv.add(t);
            }
        }
        Iterable $this$all$iv = (List) destination$iv$iv;
        boolean matchAllTypeConditions = true;
        if (!($this$all$iv instanceof Collection) || !((Collection) $this$all$iv).isEmpty()) {
            Iterator<T> it = $this$all$iv.iterator();
            while (true) {
                if (it.hasNext()) {
                    if (!it.next().toString().contains(value)) {
                        matchAllTypeConditions = false;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        if (matchAllTypeConditions) {
            return objectReader.read(this);
        }
        return null;
    }

    private final boolean shouldSkip(ResponseField field) {
        for (ResponseField.Condition condition : field.getConditions()) {
            if (condition instanceof ResponseField.BooleanCondition) {
                Boolean conditionValue = (Boolean) this.variableValues.get(((ResponseField.BooleanCondition) condition).getVariableName());
                if (((ResponseField.BooleanCondition) condition).isInverted()) {
                    if (Intrinsics.areEqual((Object) conditionValue, (Object) true)) {
                        return true;
                    }
                } else if (Intrinsics.areEqual((Object) conditionValue, (Object) false)) {
                    return true;
                }
            }
        }
        return false;
    }

    private final <V> V checkValue(ResponseField field, V v) {
        if (field.getOptional() || v != null) {
            return v;
        }
        throw new NullPointerException("corrupted response reader, expected non null value for " + field.getFieldName());
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000V\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0006\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010 \n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\b\u0004\u0018\u00002\u00020\u0001B\u0017\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u0007\u001a\u00020\bH\u0016J\u001f\u0010\t\u001a\u0002H\n\"\b\b\u0000\u0010\n*\u00020\u00052\u0006\u0010\u000b\u001a\u00020\fH\u0016¢\u0006\u0002\u0010\rJ\b\u0010\u000e\u001a\u00020\u000fH\u0016J\b\u0010\u0010\u001a\u00020\u0011H\u0016J(\u0010\u0012\u001a\n\u0012\u0006\u0012\u0004\u0018\u0001H\n0\u0013\"\b\b\u0000\u0010\n*\u00020\u00052\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u0002H\n0\u0015H\u0016J\b\u0010\u0016\u001a\u00020\u0017H\u0016J%\u0010\u0018\u001a\u0002H\n\"\b\b\u0000\u0010\n*\u00020\u00052\f\u0010\u0019\u001a\b\u0012\u0004\u0012\u0002H\n0\u001aH\u0016¢\u0006\u0002\u0010\u001bJ\b\u0010\u001c\u001a\u00020\u001dH\u0016R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0004¢\u0006\u0002\n\u0000¨\u0006\u001e"}, d2 = {"Lcom/apollographql/apollo/api/internal/SimpleResponseReader$ListItemReader;", "Lcom/apollographql/apollo/api/internal/ResponseReader$ListItemReader;", "field", "Lcom/apollographql/apollo/api/ResponseField;", "value", "", "(Lcom/apollographql/apollo/api/internal/SimpleResponseReader;Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Object;)V", "readBoolean", "", "readCustomType", "T", "scalarType", "Lcom/apollographql/apollo/api/ScalarType;", "(Lcom/apollographql/apollo/api/ScalarType;)Ljava/lang/Object;", "readDouble", "", "readInt", "", "readList", "", "listReader", "Lcom/apollographql/apollo/api/internal/ResponseReader$ListReader;", "readLong", "", "readObject", "objectReader", "Lcom/apollographql/apollo/api/internal/ResponseReader$ObjectReader;", "(Lcom/apollographql/apollo/api/internal/ResponseReader$ObjectReader;)Ljava/lang/Object;", "readString", "", "apollo-api"}, k = 1, mv = {1, 4, 0})
    /* compiled from: SimpleResponseReader.kt */
    private final class ListItemReader implements ResponseReader.ListItemReader {
        private final ResponseField field;
        final /* synthetic */ SimpleResponseReader this$0;
        private final Object value;

        public ListItemReader(SimpleResponseReader this$02, ResponseField field2, Object value2) {
            Intrinsics.checkParameterIsNotNull(field2, "field");
            Intrinsics.checkParameterIsNotNull(value2, "value");
            this.this$0 = this$02;
            this.field = field2;
            this.value = value2;
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public <T> List<T> readList(Function1<? super ResponseReader.ListItemReader, ? extends T> function1) {
            Intrinsics.checkParameterIsNotNull(function1, "block");
            return DefaultImpls.readList(this, function1);
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public <T> T readObject(Function1<? super ResponseReader, ? extends T> function1) {
            Intrinsics.checkParameterIsNotNull(function1, "block");
            return (T) DefaultImpls.readObject(this, function1);
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public String readString() {
            Object obj = this.value;
            if (obj != null) {
                return (String) obj;
            }
            throw new TypeCastException("null cannot be cast to non-null type com.kt.String");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public int readInt() {
            Object obj = this.value;
            if (obj != null) {
                return BigDecimalKt.toNumber((BigDecimal) obj).intValue();
            }
            throw new TypeCastException("null cannot be cast to non-null type com.apollographql.apollo.api.BigDecimal /* = java.math.BigDecimal */");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public long readLong() {
            Object obj = this.value;
            if (obj != null) {
                return BigDecimalKt.toNumber((BigDecimal) obj).longValue();
            }
            throw new TypeCastException("null cannot be cast to non-null type com.apollographql.apollo.api.BigDecimal /* = java.math.BigDecimal */");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public double readDouble() {
            Object obj = this.value;
            if (obj != null) {
                return BigDecimalKt.toNumber((BigDecimal) obj).doubleValue();
            }
            throw new TypeCastException("null cannot be cast to non-null type com.apollographql.apollo.api.BigDecimal /* = java.math.BigDecimal */");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public boolean readBoolean() {
            Object obj = this.value;
            if (obj != null) {
                return ((Boolean) obj).booleanValue();
            }
            throw new TypeCastException("null cannot be cast to non-null type com.kt.Boolean");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public <T> T readCustomType(ScalarType scalarType) {
            Intrinsics.checkParameterIsNotNull(scalarType, "scalarType");
            return (T) this.this$0.scalarTypeAdapters.adapterFor(scalarType).decode(CustomTypeValue.Companion.fromRawValue(this.value));
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public <T> T readObject(ObjectReader<T> objectReader) {
            Intrinsics.checkParameterIsNotNull(objectReader, "objectReader");
            Object obj = this.value;
            if (obj != null) {
                return objectReader.read(new SimpleResponseReader((Map) obj, this.this$0.variableValues, this.this$0.scalarTypeAdapters, null));
            }
            throw new TypeCastException("null cannot be cast to non-null type com.kt.collections.Map<com.kt.String, com.kt.Any>");
        }

        @Override // com.apollographql.apollo.api.internal.ResponseReader.ListItemReader
        public <T> List<T> readList(ListReader<T> listReader) {
            List values;
            T t;
            Intrinsics.checkParameterIsNotNull(listReader, "listReader");
            Object obj = this.value;
            if (obj != null) {
                List values2 = (List) obj;
                List $this$map$iv = values2;
                Collection destination$iv$iv = new ArrayList(CollectionsKt.collectionSizeOrDefault($this$map$iv, 10));
                for (Object item$iv$iv : $this$map$iv) {
                    if (item$iv$iv != null) {
                        values = values2;
                        t = listReader.read(new ListItemReader(this.this$0, this.field, item$iv$iv));
                    } else {
                        values = values2;
                        t = null;
                    }
                    destination$iv$iv.add(t);
                    values2 = values;
                }
                return (List) destination$iv$iv;
            }
            throw new TypeCastException("null cannot be cast to non-null type com.kt.collections.List<*>");
        }
    }

    private final /* synthetic */ <T> T valueFor(Map<String, ? extends Object> map, ResponseField field) {
        T t = (T) map.get(field.getResponseName());
        if (t == null) {
            return null;
        }
        Intrinsics.reifiedOperationMarker(3, "T");
        if (t instanceof Object) {
            return t;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("The value for \"");
        sb.append(field.getResponseName());
        sb.append("\" expected to be of type \"");
        Intrinsics.reifiedOperationMarker(4, "T");
        sb.append(Reflection.getOrCreateKotlinClass(Object.class).getSimpleName());
        sb.append("\" but was \"");
        sb.append(Reflection.getOrCreateKotlinClass(t.getClass()).getSimpleName());
        sb.append(Typography.quote);
        throw new ClassCastException(sb.toString());
    }
}
